import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;

//coding=utf8
/**
 * @Author: bighu
 * @Created Time : 2022年05月16日 星期一 15时01分45秒
 * @File Name: shiyan4_2.java
 * @Description:
 */
public class shiyan4_2_client{
	public static final String sorkey = "itsnotkey";
	public static void main(String[] args)throws Exception{
		Scanner scan = new Scanner(System.in);
		String algorithm = "HmacSHA512";
		byte[] byteKey = sorkey.getBytes(StandardCharsets.UTF_8);
		//sha512Hmac 是Hmac用的密钥,会被保存起来
		Mac sha512Hmac=Mac.getInstance(algorithm);
		SecretKeySpec keySpec = new SecretKeySpec(byteKey,algorithm);
		sha512Hmac.init(keySpec);
		String message = scan.nextLine();
		byte[] macData = sha512Hmac.doFinal(message.getBytes(StandardCharsets.UTF_8));
		funcSendMac(macData,message);
		scan.close();
	}

	public static void funcSendMac(byte[] data,String sordata) throws IOException, InterruptedException {
		Socket soc = new Socket("localhost",8000);
		OutputStream outputStream = soc.getOutputStream();
		outputStream.write(sordata.getBytes());
		Thread.sleep(500);
		outputStream.write(data);
		extracted(soc);
	}

	private static void extracted(Socket soc) throws IOException {
		soc.close();
	}
}